<?php
//error_reporting(0);

/**
 * 更新瀑布图片
 */

include_once($_SERVER["DOCUMENT_ROOT"]. "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/mblogv2/mod_get_mblogv2_from_api.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();

function show_pro()
{
	global $g_show;
	echo output::json("json",$g_show);
}

function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	cgi::both($g_cgival["status_id"], "status_id", 0);
	
	$g_cgival["status_id"] = intval($g_cgival["status_id"]);
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$status_id = $g_cgival["status_id"];
	if(!$g_cgival["status_id"])
	{
		throw new Exception("status_id不能为空！");
	}
	
	
	$mod_food_status_content = new db_food_status_content();
	$item = $mod_food_status_content->get_food_status_content_by_status_id($g_cgival["status_id"]);
	
	if(!$item)
	{
		throw new Exception("信息不存在！");
	}
	$pic = $item["pic"];

	$mod_food_status_content = new mod_food_status_content();
	$mod_food_status_content->update_pic_width_by_url_and_status_id($status_id,$pic,PUBU_PIC_WIDTH,true);
	
	$g_show["pic"] = "http://s3img.city.sina.com.cn/food_city/pubu/{$status_id}.jpg";
	

	$upload = new s3_upload();
	$url_info = parse_url($pic);
	
	$big_path = substr($url_info["path"],1);
	
	$bmiddle_path = str_replace("large/","bmiddle/",$big_path);
	$reset2 = $upload->show($pic)->magicwand_zomm(440)->save($bmiddle_path);

	$g_show["pic1"] = $reset2["src"];
	
	$thumbnail_path = str_replace("large/","thumbnail/",$big_path);
	$reset3 = $upload->show($pic)->magicwand_zomm(120)->save($thumbnail_path);
	$g_show["pic2"] = $reset3["src"];
	
}

try
{
//	admin_check_login();
// 	admin_check_user_priv("foodv2/main_nav.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;

